//
//  OrderViewController.m
//  YongChuanTradingArea
//
//  Created by 李冰 on 2017/9/8.
//  Copyright © 2017年 李冰. All rights reserved.
//

#import "OrderViewController.h"
#import "MineNoticeCell.h"

static NSString * const MineNoticeCellID = @"MineNoticeCell";

@interface OrderViewController ()

@end

@implementation OrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"消息";
    
    [self createUI];
    [self setupPageHeader:YES footer:YES];
    [self headerRefresh];
    // Do any additional setup after loading the view.
}

- (void)createUI{
    [self.view addSubview:self.tableView];
    self.tableView.frame = CGRectMake(0, 64, lbScreenWidth, lbScreenHeight- 64 - 49);
    self.tableView.estimatedRowHeight = 80;
    [self.tableView registerNib:[UINib nibWithNibName:MineNoticeCellID bundle:nil] forCellReuseIdentifier:MineNoticeCellID];
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 12, 0, 0);
    self.tableView.separatorColor = [UIColor colorWithHexString:@"#dcdcdc"];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MineNoticeCell *cell = [tableView dequeueReusableCellWithIdentifier:MineNoticeCellID forIndexPath:indexPath];
    cell.model = self.dataSource[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}

#pragma mark - request data
- (void)requestPageData:(void (^)(YCNetworkingStatusCode, NSArray *))statusBlock{
    __weak typeof(self) weakSelf = self;
    [LBNetworkingInstance requestGET:commonNoticeList parameters:@{@"msgType":@"1"} showHUD:YES success:^(id responseObject, NSInteger code, NSString *message) {
        if (code == YCNetworkingStatusCodeSuccess){
            NSArray * array = [NSArray yy_modelArrayWithClass:[MineNoticeModel class] json:responseObject[@"Data"]];
            statusBlock(code, array);
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableView reloadData];
            });
        }else{
            statusBlock(code, nil);
        }
    } failure:^(NSError *err) {
        statusBlock(YCNetworkingStatusCodeHTTPError, nil);
    }];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    
    return UIStatusBarStyleDefault;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
